/* 操作localStorage */
const tokenName = 'newsToken'
const historyName = 'new-History'
const channels = 'newsChannel'
// 设置token
export function setToken (token) {
  localStorage.setItem(tokenName, JSON.stringify(token))
}
// 获取token
export function getToken () {
  // 如果获取不到就获取空对象，空对象调用会返回undefined，null调用会报错
  return JSON.parse(localStorage.getItem(tokenName)) || {}
}
// 删除token
export function removeToken () {
  localStorage.removeItem(tokenName)
}
// 存储历史记录
export function setHistory (keyword) {
  localStorage.setItem(historyName, JSON.stringify(keyword))
}
// 获取历史记录 获取不到就获取空数组，不然会报错
export function getHistory () {
  return JSON.parse(localStorage.getItem(historyName)) || []
}

// 设置频道
export function setChannel (channelList) {
  localStorage.setItem(channels, JSON.stringify(channelList))
}
// 获取频道
export function getChannel () {
  return JSON.parse(localStorage.getItem(channels))
}
